# Maintainer: Markus Rathgeb <maggu2810@gmail.com>

_realname=libserialport
_commit=6f9b03e597ea7200eb616a4e410add3dd1690cb1
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.1.r399.6f9b03e
pkgrel=1
pkgdesc="cross-platform library for accessing serial ports (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://sigrok.org/wiki/Libserialport"
license=('spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("git://sigrok.org/${_realname}#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "0.1.1.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare(){
  cd ${srcdir}/${_realname}
  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static
  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  PATH="${srcdir}/build-${MINGW_CHOST}/src/.libs:$PATH" make check || true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
